/* 
 * Bitmain Tech, Home of Professional Bitmain Tech
 * Copyright 2014 Bitmain Tech Inc. and/or its affiliates and other contributors
 * as indicated by the @author tags. All rights reserved.
 * See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 */
package com.bitmain.mmst.core.base;

import java.util.Locale;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.context.support.WebApplicationContextUtils;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;
import org.springframework.web.util.WebUtils;

import com.bitmain.mmst.common.consts.Consts;

/**
 * 控制层基类
 * 
 * @author Kweny - enkun.jiang@bitmain.com
 * @since 2015年12月11日
 */
public abstract class BasicController implements Consts {
	
	public void setSessionAttribute(HttpServletRequest request, String name, Object value) {
		WebUtils.setSessionAttribute(request, name, value);
	}
	
	public Object getSessionAttribute(HttpServletRequest request, String name) {
		return WebUtils.getSessionAttribute(request, name);
	}
	
	public String getMessage(HttpServletRequest request, String code, Object... args) {
		Locale locale = (Locale) WebUtils.getSessionAttribute(request, SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME);
		return WebApplicationContextUtils.getWebApplicationContext(request.getServletContext()).getMessage(code, args, locale);
	}
}
